package my.study.java.lang.reflect.Proxy.examples;

import java.lang.reflect.Proxy;

public class Main2 {
	public static void consumer(Animal iface) {
		iface.eat();
		iface.shout("bonobo");
	}

	/**
	 * 打印代理方法的调用次数
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Dog real = new Dog();
		consumer(real);
		Animal proxy = (Animal) Proxy.newProxyInstance(
				Animal.class.getClassLoader(),
				new Class[] { Animal.class }, new DynamicProxyHandler(real));
		consumer(proxy);
		consumer(proxy);
	}
}

